package util;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.example.administrator.text.AppointTimeActivity;
import com.example.administrator.text.AuthorizationActivity;
import com.example.administrator.text.HomeActivity;
import com.example.administrator.text.ModifyInformationActivity;
import com.example.administrator.text.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import org.apache.log4j.Logger;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import app.MyApplication;
import cn.jpush.android.api.JPushInterface;
import data.SharedPreferencesUtils;
import util.BReceiverUtil.AlarmReceiver;
import util.BReceiverUtil.SMSBroadcastReceiver;
import util.fileUtil.ZipUtils;
import view.diaLogView.CrowdRetunDialog;
import view.diaLogView.EntryPromptDialog;
import view.diaLogView.ScanDialog;
import view.diaLogView.UploadDialog;
/**
 * Created by 刘小斌 on 2016/6/22.
 * 页面的辅助类
 */
public class HomeUtil<T> {
    private static HomeUtil homeUtil;
    private Handler mHandler;
    private String sessionId ="";
    private String mFwq = "";
    private int mSaveComboInt = 0;
    private boolean mNetWorkstate = true; //如果切换服务器，走通了代理，就变化状态，10s后恢复
    private Logger mLogger = Logger.getLogger(HomeUtil.class);
    public static ExecutorService mHUExecutorService = Executors.newFixedThreadPool(2); //创建一个线程池
//    private AMapLocationClient mLocationClient = null;
    public static String XIALA = "xiala";                           //首页的 下拉
    public static String appNetWorkstate = "appNetWorkstate";       //app的外网网络状态
    public static String ENTRY = "ENTRY";                          //登录页
    public static String ZHUYENETWORKING = "ZHUYEnetworking";     //主页非深大上网的标识
    public static String SZNETWORKING = "SZEnetworking";         //主页深大上网的标识
    public static String ZHUYE = "ZHUYE";                       //主页EntryPromp
    public static String ENTRYPROMP = "ENTRYPROMP";            //登录和逛逛页的标识
    public static final String mHUAppVer = "AppVer";          //存在文件中的App的版本号
    public static final String mSTUDENPhone = "Studentphone";   //存在文件中的key 学生的学号
    public static final String mSTUDENPSSWORD = "StudentPassword";//存在文件中的key 或者学生密码
    public static final String mHUWePhone = "phone";           //存在文件中的key 用户的手机号
    public static final String mNICKNAME = "nickname";        //存在文件中的key 用户的的昵称
    public static final String mUseridDB = "userid";         //存在文件中的key 项目的userid
    public static final String mHSBinding = "no";           //存在文件中的key
    public static final String mTokenDB = "token";         //存在文件中的key 项目的Token
    public static final String mCrashError = "crashError";//存在文件中的key  记录是否有崩溃信息的记录
    public static final String mChatToken = "chatToken"; //存在文件中的key  融云的Token
    public static final String mFWQ = "WiFiFWQ";       //存在文件中项目的代理服务器地址
    public static final String mFWQMAC = "wifi_mac";              //存在文件中项目的服务器地址
    public static final String mVIPSTATE = "vipState";         //存在文件中vip的状态
    public static final String mVIPTime = "vipTime";          //存在文件vip 的时长
    public static final String mVIPCombonum= "Combonum";     //存在文件vip 的商品id
    public static final String mPledge = "pledge";         //存在文件vip 的商品的价格
    public static final String mMoneyTime = "MoneyTime"; //时长联网成功的当前时间
    public static final String mNetworkingTime = "NetworkingTime";                 //时长联网 的时间  V
    public static final String mAppPattern = "App_Pattern";                       //app的模式
    public static final String mAppPatternArray = "App_PatternArray";            //app的模式数组
    public static final String mPackage_Expire_time = "Package_Expire_time";    //套餐的到期时间
    public static final String mPackage_RemainingDays = "Package_RemainingDays"; //套餐剩余天数
    public static final String mPackage_AttachCombo = "Package_attachCombo";   //子套餐的集合
    public static final String mPackage_deviceCount = "Package_deviceCount";    //可授权可数
    public static final String mAppNoticeNoticeId = "AppNoticeNoticeId";       //app中的通知
    public static final String AppAltairPushIden = "AppAltair_pushIden";      //给app设置的区域标签
    public static final String AppAltairPushIden_Statr = "AppAltair_pushIden_statr";      //记录app 标签是否有变化
    public static final String AppAgainState = "AppAgainState";      //记录app是否从后台回到前台并更新相关状态

    public static HomeUtil getHemeUtilNew() {
        if (homeUtil == null) {
            synchronized (HomeUtil.class){
                if(homeUtil == null){
                    return homeUtil = new HomeUtil();
                }
            }
            return homeUtil = new HomeUtil();
        }
        return homeUtil;
    }

    /**
     * 返回一个Handler对象
     */
    public Handler getHandlerNew(){
        if(mHandler == null){
            mHandler = new Handler();
        }
        return mHandler;
    }

    /**
     * 初始化DisplayImageOptions
     */
    public DisplayImageOptions getDisplayImageOptions(boolean state, int movieResId) {
        DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(state)//设置下载的图片是否缓存在内存中
                .cacheOnDisk(true)//设置下载的图片是否缓存在SD卡中
                .showImageOnLoading(movieResId)//设置图片在下载期间显示的图片
                .showImageOnFail(movieResId)//设置图片加载/解码过程中错误时候显示的图片
                .showImageForEmptyUri(movieResId)//设置图片Uri为空或是错误的时候显示的图片
                .bitmapConfig(Bitmap.Config.RGB_565)//设置图片的质量
                .imageScaleType(ImageScaleType.IN_SAMPLE_INT)//设置图片的缩放类型，该方法可以有效减少内存的占用
                .build();
        return displayImageOptions;
    }

    /**
     * 设置状态栏
     */
    public void getStatusBar(Context context, View view) {
        //透明状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = ((Activity) context).getWindow();
            // Translucent status bar
            window.setFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } else {
            if (view != null) {
                ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
                int widt = getInformation.getNewGetInformation(context).getIWidth().widthPixels;
                layoutParams.width = widt;
                layoutParams.height = widt / 7;
                view.setLayoutParams(layoutParams);
                LogUtil.eE("Window", "       进来了状态栏        " + (widt / 7));
            }
        }

        //透明状态栏
        ((Activity)context).getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //透明导航栏
        //((Activity)context).getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }

    /**
     * 加载ViewPager中的小圆点
     *
     * @param context       上下文
     * @param movieResId    ImagerView 的样式
     * @param choice        默认是否选择
     *                      是否要加1
     * @param mListView     ViewPager中的View
     * @param mListIv       共有几个小图标
     * @param mLinearLayout 所在的布局
     */
    public void getViewPagerCircularDot(Context context, int movieResId, boolean choice, boolean choice1, List<T> mListView, List<ImageView> mListIv, LinearLayout mLinearLayout) {

        if (mListView != null && mListView.isEmpty()) {
            return;
        }

        ImageView mImageView = null;
        // 布局参数
        LinearLayout.LayoutParams params =
                new LinearLayout.LayoutParams(
                        ViewGroup.MarginLayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);

        params.leftMargin = 14;//控件到布局的距离
        if (choice1) {
            for (int i = 0; i < mListView.size() + 1; i++) {
                Log.e("SIAE", "mListView" + mListView.size());
                mImageView = new ImageView(context);
                mImageView.setImageResource(movieResId);
                // 默认不选择
                mImageView.setSelected(choice);
                // 设置布局参数
                mImageView.setLayoutParams(params);
                // 添加到布局中
                mLinearLayout.addView(mImageView);
                // 添加到集合中
                mListIv.add(mImageView);
            }
            Log.e("SIAE", "mListIv" + mListIv.size());

        } else{

            for (int i = 0; i < mListView. size(); i++) {
                mImageView = new ImageView(context);
                mImageView.setImageResource(movieResId);
                // 默认不选择
                mImageView.setSelected(choice);
                // 设置布局参数
                mImageView.setLayoutParams(params);
                // 添加到布局中
                mLinearLayout.addView(mImageView);
                // 添加到集合中
                mListIv.add(mImageView);
            }
            Log.e("SIAE", "mListIv" + mListIv.size());
        }
    }

    /**
     * 获取短信
     */
    public void getMessage(Context context, final EditText editText,SMSBroadcastReceiver smsBroadcastReceiver) {
        if(smsBroadcastReceiver == null){smsBroadcastReceiver = new SMSBroadcastReceiver();}
        IntentFilter intentFilter = new IntentFilter(SMSBroadcastReceiver.SMS_RECEIVED_ACTION);
        intentFilter.setPriority(Integer.MAX_VALUE);
        context.registerReceiver(smsBroadcastReceiver, intentFilter);
        smsBroadcastReceiver.setOnReceivedMessageListener(new SMSBroadcastReceiver.IMessageListener() {
            @Override
            public void onReceived(String message) {
                editText.setText(message);
            }
        });
    }

    /**
     * 获取短信
     * @param fwq 服务器
     * @param tv  获取短信TV
     */
    public void obtainVerification(final Context context, Map<String, Object> map, String fwq, final TextView tv, final int shui,final int type) {

        GreenTreeNetworkUtil.getInstance().doPost(context,fwq,1,map, new RequestDataCallback() {
            @Override
            public void onSuccess(String response) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    String code = jsonObject.getString("code");
                    LogUtil.eE("Gson", response);
                    if (code.equals("1")) {
                        TimeCountUtil time = new TimeCountUtil(context, 30, tv, shui,type);
                        if (shui == 0) {
                            Toast.makeText(context, R.string.success_sms, Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(context, R.string.success_phone, Toast.LENGTH_SHORT).show();
                        }
                    } else if (code.equals("-1")) {
                        if (shui == 0) {
                            Toast.makeText(context, R.string.fail_sms, Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(context, R.string.fail_phone, Toast.LENGTH_SHORT).show();
                        }
                    } else if (code.equals("0")) {
                        Toast.makeText(context, "发送失败", Toast.LENGTH_SHORT).show();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Throwable error) {
                StringUtil.getStringUtilNew().getExceptionCode(context, error.toString());
            }
        });
    }
    /**
     * @param root         最外层布局，需要调整的布局
     * @param scrollToView 被键盘遮挡的scrollToView，滚动root,使scrollToView在root可视区域的底部
     */
    public void getControlKeyboardLayout(final View root, final View scrollToView) {
        root.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect rect = new Rect();
                root.scrollTo(0, 0);
                //获取root在窗体的可视区域
                root.getWindowVisibleDisplayFrame(rect);
                //获取root在窗体的不可视区域高度(被其他View遮挡的区域高度)
                int rootInvisibleHeight = root.getRootView().getHeight() - rect.bottom;

                //if(rootInvisibleHeight>)
                //若不可视区域高度大于100，则键盘显示
                if (rootInvisibleHeight > 100) {
                    int[] location = new int[2];
                    //获取scrollToView在窗体的坐标
                    scrollToView.getLocationInWindow(location);
                    Log.e("scrollToView", "不可视区域高度" + rootInvisibleHeight);
                    Log.e("scrollToView", "view到底部的距离" + (root.getRootView().getHeight() - location[1] + scrollToView.getHeight()));
                    int viewButton = root.getRootView().getHeight() - location[1] + scrollToView.getHeight();//view到底部的距离
                    if (viewButton < rootInvisibleHeight) {
                        //计算root滚动高度，使scrollToView在可见区域
                        int srollHeight = (location[1] + scrollToView.getHeight()) - rect.bottom;
                        root.scrollTo(0, srollHeight);
                    }
                } else {
                    //键盘隐藏
                    root.scrollTo(0, 0);
                }
            }
        });
    }

    /**
     * 关闭Dialog
     */
    public void getDialogDismiss(View view, final Dialog dialog) {
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }

    /**
     * 游客身份登录
     * jumd 0 正常情况进入主页 1 进入登录选择页
     */
    public void getTourist(final Context context, final String fWQString, final UploadDialog uploadDialog,final ImageView imageView,final int jumd) {

        if (SharedPreferencesUtils.getParam(context, HomeUtil.mTokenDB, "").equals("")) {
            SharedPreferencesUtils.setParam(context, HomeUtil.mTokenDB, "unll");
        }
        if (SharedPreferencesUtils.getParam(context, HomeUtil.mUseridDB, "").equals("")) {
            SharedPreferencesUtils.setParam(context, HomeUtil.mUseridDB, "0");
        }
        String appId = getInformation.getNewGetInformation(context).getAndroidMD5();
        final String token = (String) SharedPreferencesUtils.getParam(context, HomeUtil.mTokenDB, "");
        final String id = (String) SharedPreferencesUtils.getParam(context,HomeUtil.mUseridDB,"");
        final HashMap<String,Object> mMap = new HashMap<>();
        mMap.put("soleCode",appId);
        mMap.put("token",token);
        mMap.put("userid",id);
        mMap.put("ver",getInformation.getNewGetInformation(context).getVersion());
        mMap.put("mac",getInformation.getNewGetInformation(context).getIMAC());
        mMap.put("deviceType",getInformation.getNewGetInformation(context).getInfoPhone());
        mMap.put("deviceVer",getInformation.getNewGetInformation(context).getInfoPhoneType());
        mMap.put("ip",getInformation.getNewGetInformation(context).getI_IP());
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(mMap); //参数包
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngLogin_visitorLogin,stringJson,token,id,time);
        Map map = StringUtil.getStringUtilNew().getMapNew(context,stringJson,token,id,Url.mStirngLogin_visitorLogin,stirngSign,time);
        mLogger.info("游客---getTourist--->fWQString--"+fWQString+"stirngSign"+stringJson+"...NF_callid..."+map.get("NF_callid"));
        LogUtil.eE("fwq",fWQString+""+"deviceType"+getInformation.getNewGetInformation(context).getInfoPhone()+"devicVer"+getInformation.getNewGetInformation(context).getInfoPhoneType()+"ip   "+getInformation.getNewGetInformation(context).getI_IP()+"...NF_callid..."+map.get("NF_callid")+"..stringJson.."+stringJson);
        GreenTreeNetworkUtil.getInstance().doPost(context,fWQString,1,map,new RequestDataCallback() {
            @Override public void onSuccess(String response) {
                try {
                    if(uploadDialog !=null){uploadDialog.dismiss();}
                    mLogger.info("getTourist--->onSuccess--->"+"String"+response);
                    LogUtil.eE("GSON", response);
                    JSONObject jsonObject = new JSONObject(response);
                    if (jsonObject.getInt("code") == 1) {
                        setWeInformation(context,jsonObject);
                        final String token = jsonObject.getString("token");
                        final String chatToken = jsonObject.getString("chatToken");
                        if(jsonObject.has("cloudUrl")){
                            String cloudUrl = jsonObject.getString("cloudUrl");
                            Url.getUrlNew().setAppIP(cloudUrl+":8080/wifi/TransferServlet");
                        }
                        if(jsonObject.getInt("status") == 0){
                            JumpActivityUtils.getInstance().jumEntrtPrompt(context);
                            ((Activity)context).finish();
                        }else {
                            touristEntry(context,token,chatToken);
                        }
                    } else if (jsonObject.getInt("code") == -2) {
                        CrowdRetunDialog crowdRetunDialog = new CrowdRetunDialog(context);
                        crowdRetunDialog.show();

                    } else {Toast.makeText(context,context.getString(R.string.FWQ),Toast.LENGTH_SHORT).show();}

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override public void onFailure(Throwable error) {
                if(uploadDialog !=null){uploadDialog.dismiss();}
                JumpActivityUtils.getInstance().jumEntrtPrompt(context);
            }
        });
    }

    /**
     * 登录接口
     * @param context   上下文
     * @param phone  手机号
     * @param password  密码
     * @param uploadDialog  Dialog对象
     * EntryPromptDialog   登录时弹出的dialog 不需要可传null
     * type 哪里调用
     */
    public void getEntry(final Context context, final String phone, String password, final UploadDialog uploadDialog,final EntryPromptDialog entryPromptDialog,final String type) {
        if(uploadDialog != null ){
            uploadDialog.getStringShow("登录中");
        }
        String token = (String) SharedPreferencesUtils.getParam(context, HomeUtil.mTokenDB, "");
        String id = (String) SharedPreferencesUtils.getParam(context, HomeUtil.mUseridDB, "");
        HashMap<String, Object> map = new HashMap<>();
        map.put("accountType", 1);
        map.put("account",phone);
        if(password.length()==5){map.put("pwd","");map.put("authcode",password);}
        else {
        map.put("pwd", StringUtil.getStringUtilNew().getMD5String(password)); map.put("authcode","");}
        map.put("soleCode",getInformation.getNewGetInformation(context).getAndroidMD5());
        map.put("mac",getInformation.getNewGetInformation(context).getIMAC());
        map.put("deviceType",getInformation.getNewGetInformation(context).getInfoPhone());
        map.put("deviceVer",getInformation.getNewGetInformation(context).getInfoPhoneType());
        map.put("ver",getInformation.getNewGetInformation(context).getVersion());
        map.put("ip",getInformation.getNewGetInformation(context).getI_IP());
        LogUtil.eE("","登入ip    "+getInformation.getNewGetInformation(context).getI_IP());
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(map); //参数包
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngLogin_manuLogin,stringJson,token,id,time);
        Map map1 = StringUtil.getStringUtilNew().getMapNew(context,stringJson,token,id,Url.mStirngLogin_manuLogin,stirngSign,time);
        LogUtil.eE("fwq",MyApplication.getApp().getFWQString()+"");
        mLogger.info("登录--getEntry--->stringJson--"+stringJson+"fwq"+MyApplication.getApp().getFWQString()+"...NF_callid..."+map.get("NF_callid"));
        GreenTreeNetworkUtil.getInstance().doPost(context,MyApplication.getApp().getFWQString(),1,map1,new RequestDataCallback() {
            @Override
            public void onSuccess(String response) {
                try {
                    Log.e("response", "          " + response);
                    mLogger.info("getEntry--->onSuccess--->"+"String"+response);
                    JSONObject jsonObject = new JSONObject(response);
                    String code = jsonObject.getString("code");
                    if( uploadDialog != null){
                        uploadDialog.dismiss();
                    }
                    if (code.equals("1")) {
                        setWeInformation(context,jsonObject);
                        SharedPreferencesUtils.setParam(context,HomeUtil.mHUWePhone,phone);
                        SharedPreferencesUtils.setParam(context,HomeUtil.mTokenDB,jsonObject.getString("token"));
                        SharedPreferencesUtils.setParam(context,HomeUtil.mUseridDB,jsonObject.getString("userid"));
                        SharedPreferencesUtils.setParam(context,HomeUtil.mChatToken,jsonObject.getString("chatToken"));
                        HomeUtil.getHemeUtilNew().saveCombo(context,0,null);
                        if(type.equals(ENTRYPROMP)){
                           JumpActivityUtils.getInstance().jumpHome(context,"");
                            ((Activity)context).finish();
                        }else if(type.equals(ENTRY)){
                            if(entryPromptDialog !=null){entryPromptDialog.dismiss();}
                        }else if(type.equals(ZHUYENETWORKING)){
                            if(entryPromptDialog !=null){entryPromptDialog.dismiss();}
                            NetWorkstateUtil.getInstance().getNetworking(context,uploadDialog,ZHUYENETWORKING);
                        }else if(type.equals(SZNETWORKING)){
                            if(entryPromptDialog !=null){entryPromptDialog.dismiss();}
                            EntryPromptDialog entryPromptDialog = new EntryPromptDialog(context,EntryPromptDialog.mStringEntry,"");
                            entryPromptDialog.show();
                        }
                     /*   //登录融云
                        if (MyApplication.getApp().getStatus() != 0) {
                            String id = ImSPDatasUtil.getInstance().getLocalUserid(context);
                            String chattoken = ImSPDatasUtil.getInstance().getLocalChattoken(context);
                            LoginRongImUtil.getInstance().loginRIM(context, chattoken, id);
                        }*/
                    } else if (code.equals("0")) {
                        uploadDialog.dismiss();
                        Toast.makeText(context, "验证未通过", Toast.LENGTH_SHORT).show();
                    } else {
                        uploadDialog.dismiss();
                        Toast.makeText(context,context.getString(R.string.FWQ), Toast.LENGTH_SHORT).show();
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Throwable error) {
                uploadDialog.dismiss();
                StringUtil.getStringUtilNew().getExceptionCode(context, error.toString());
            }
        });
    }

    /**
     * 解析二维码的信息
     */
    public void getSessionId(Context context,String gson,String id,String token){

        if(!gson.equals("")){
            try {
                if(gson.contains("=")){
                    String gson1 = gson.substring(gson.indexOf("newfi=")+6,gson.length());
                    gson1 = gson1.substring(0,gson1.indexOf("}")+1);
                    JSONObject jsonObject = new JSONObject(gson1);
                    String from = jsonObject.getString("from");
                    if(!from.equals("") && from.equals("Altair")){
                        mLogger.info("getSessionId--->二维码的信息-2-"+gson);
                        String forStirng = jsonObject.getString("for");
                        if(jsonObject.has("sessionid")){
                            sessionId = jsonObject.getString("sessionid");
                        }
                        if(!forStirng.equals("") && forStirng.equals("bamlogin")){
                            String url = jsonObject.getString("url");
                            LogUtil.eE("","url"+url);
                            ScanDialog scanDialog = new ScanDialog(context,id,token,sessionId,forStirng,url);
                            scanDialog.show();
                        }else if(!forStirng.equals("") && forStirng.equals("appAccreditNet")){
                            JumpActivityUtils.getInstance().jumAuthorization(context,AuthorizationActivity.TYPE,sessionId);
                        }else if(!forStirng.equals("") && forStirng.equals("pcAccreditNet")){
                            JumpActivityUtils.getInstance().jumAuthorization(context,"pc",sessionId);
                        }else if(!forStirng.equals("") && forStirng.equals("NewProtect")){
                            String uuid = jsonObject.getString("uuid");
                            ScanDialog scanDialog = new ScanDialog(context,id,token,uuid,forStirng,"");
                            scanDialog.show();
                        }else if(!forStirng.equals("") && forStirng.equals("pcAccreditNet2")){
                            String sessionid = jsonObject.getString("sessionid");
                            if(MyApplication.getApp().getSiteAreaid() == 1){
                                EntryPromptDialog entryPromptDialog = new EntryPromptDialog(context,EntryPromptDialog.mStringEntry,sessionid);
                                entryPromptDialog.show();
                            }else {
                                ssidPCJurisdiction(context,sessionid);
                            }
                        }else {
                            getSessionIdNo(context,gson);
                        }
                    }else {
                        getSessionIdNo(context,gson);
                    }
                }else {
                    getSessionIdNo(context,gson);
                }
            } catch (JSONException e) {
                e.printStackTrace();
                getSessionIdNo(context,gson);
            }}
    }

    /**
     * 解析二维码失败
     */
    private void getSessionIdNo(Context context,String gson){
        if(gson.contains("?")){
            gson = gson.substring(0,gson.indexOf("?"));
            if(StringUtil.getStringUtilNew().getStateHttp(gson)){
                JumpActivityUtils.getInstance().jumpWebView(context,gson,"");
            }else {
                Toast.makeText(context,gson,Toast.LENGTH_SHORT).show();
            }
        }else {
            Toast.makeText(context,gson,Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 判断授权pc 联网的权限
     */
    private void ssidPCJurisdiction(Context context,String sessionid){
        int pattern = StringUtil.getStringUtilNew().judgeUIType(MyApplication.getApp().getmPattern());
        if( pattern == 1){
            JumpActivityUtils.getInstance().jumpAppointTime(context,AppointTimeActivity.SSID_PC_NetWorkstate,sessionid);
        }else {
            String id = (String) SharedPreferencesUtils.getParam(context,HomeUtil.mUseridDB,"");
            String token = (String) SharedPreferencesUtils.getParam(context,HomeUtil.mTokenDB, "");
            JumpActivityUtils.getInstance().jumpApiCloud5(context,1,id,token,sessionid);
        }
    }

    /**
     * 解析保存相关个人信息
     */
    private void setWeInformation(Context context,JSONObject jsonObject) throws JSONException {

        if(jsonObject.has("nickname")){
          SharedPreferencesUtils.setParam(context, HomeUtil.mNICKNAME, jsonObject.getString("nickname"));
        }

        if(jsonObject.has("sex")){
            SharedPreferencesUtils.setParam(context, ModifyInformationActivity.SEX, jsonObject.getInt("sex"));
        }

        if(jsonObject.has("selfdom")){
            SharedPreferencesUtils.setParam(context,ModifyInformationActivity.SELFSOM, jsonObject.getString("selfdom"));
        }

        if(jsonObject.has("pwd")){
            SharedPreferencesUtils.setParam(context,ModifyInformationActivity.PWD, jsonObject.getInt("pwd"));
        }

        if(jsonObject.has("niuNum")){
            SharedPreferencesUtils.setParam(context,ModifyInformationActivity.NIUNUM,jsonObject.getInt("niuNum"));
        }

        if(jsonObject.has("headimg")){

            SharedPreferencesUtils.setParam(context,ModifyInformationActivity.WEHEAD,jsonObject.getString("headimg"));
        }

        if(jsonObject.has("userid")){
            String userid = (String)SharedPreferencesUtils.getParam(context, HomeUtil.mUseridDB,"");
            if(!jsonObject.getString("userid").equals(userid)){
                SharedPreferencesUtils.setParam(context,HomeUtil.AppAltairPushIden_Statr,false);
            }
            SharedPreferencesUtils.setParam(context, HomeUtil.mUseridDB, jsonObject.getString("userid"));
            setPushAurora(context);
        }

        if(jsonObject.has("isLogUploads")){
            if(jsonObject.getInt("isLogUploads") == 1){
                Url.getUrlNew().setLogUploadsState(true);
            }else {
                Url.getUrlNew().setLogUploadsState(false);
            }
        }
    }

    /**
     * 设置极光的标签
     */
    public void setPushAurora(Context context){
        boolean pushIden_Statr = (boolean) SharedPreferencesUtils.getParam(context,HomeUtil.AppAltairPushIden_Statr,false);
            if(!pushIden_Statr){
                String pushIden = (String)SharedPreferencesUtils.getParam(context, HomeUtil.AppAltairPushIden,"");
                String userid = (String)SharedPreferencesUtils.getParam(context, HomeUtil.mUseridDB,"");
                Set<String> set = new LinkedHashSet<>();
                if(!pushIden.equals("")){
                    set.add(pushIden);             //名字任意，可多添加几个
                }
                if(!userid.equals("")){
                    set.add(userid);             //名字任意，可多添加几个
                }
                mLogger.info(".......setPushAurora......设置极光的tags..pushIden.."+pushIden+"..userid..."+userid);
                JPushInterface.setTags(context,434364845,set);
            }
    }

    /**
     * 查询 时长
     */
    public void getVip(final Context context,String id,String tolen) {
        String url;
        HashMap map = new HashMap<>();
        map.put("userid", id);
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(map); //参数包
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngpcDeal_selectBalance, stringJson, tolen, id, time);
        Map map1 = StringUtil.getStringUtilNew().getMapNew(context,stringJson, tolen, id, Url.mStirngpcDeal_selectBalance, stirngSign, time);
        if (NetUtils.getInstance(context.getApplicationContext()).getNetWorkTeyt() == 0) {
            url = Url.getUrlNew().getAppIP();
        } else {
            url = MyApplication.getApp().getFWQString();
        }
        mLogger.info("getVip()--->查询时长--fwq" + url + "stirngSign" + stirngSign+"...NF_callid..."+map1.get("NF_callid"));
        GreenTreeNetworkUtil.getInstance().doPost(context,url,3000,map1, new RequestDataCallback() {
            @Override
            public void onSuccess(String response) {
                try {
                    mLogger.info("getVip()--->查询时长--onSuccess()" +response);
                    JSONObject jsonObject = new JSONObject(response);
                    String code = jsonObject.getString("code");
                    LogUtil.eE("", response);
                    if (code.equals("1")) {
                        SharedPreferencesUtils.setParam(context, HomeUtil.mVIPTime,jsonObject.getInt("longTime"));
                    } else if (code.equals("-2")) {
                        /*CrowdRetunDialog crowdRetunDialog = new CrowdRetunDialog(context);
                        crowdRetunDialog.show();*/
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Throwable error) {
            }
        });
    }

    public void setWiFiView(final Context context){
        setSiteAreaid(context,0);

    }

    /**
     * 更新区域id
     */
    public void setSiteAreaid(final Context context,final int type){

        HashMap<String,Object> json = new HashMap<>();
        String id = (String) SharedPreferencesUtils.getParam(context, HomeUtil.mUseridDB, "");
        if(id.equals("")){
            json.put("userid",0);
        }else {json.put("userid",id);}
        json.put("visitType",1);
        json.put("ip",getInformation.getNewGetInformation(context).getI_IP());
        json.put("mac",getInformation.getNewGetInformation(context).getIMAC());
        json.put("apMac",getInformation.getNewGetInformation(context).getWiFiMac());
        json.put("apName",getInformation.getNewGetInformation(context).getWIFIName());
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(json); //参数包
        final long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngVersion_isAlive,stringJson,"null","0",time);
        Map map = StringUtil.getStringUtilNew().getMapNew(context,stringJson,"null","0",Url.mStirngVersion_isAlive,stirngSign,time);
        if(type == 0 || type == 3){
            mFwq = (String) SharedPreferencesUtils.getParam(context,HomeUtil.mFWQ,"");
        }
        mLogger.info("setSiteAreaid()--->更新区域id--"+"fwq--"+mFwq+"..type.."+type+stringJson+"...NF_callid..."+map.get("NF_callid"));
        GreenTreeNetworkUtil.getInstance().doPost(context,mFwq,1500,map,new RequestDataCallback() {
            @Override public void onSuccess(String response) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    mLogger.info("setSiteAreaid()--->onSuccess--->"+"String--"+response+"..mNetWorkstate.."+mNetWorkstate);
                    if (jsonObject.getInt("code") == 1){
                        LogUtil.eE("Altair_appIP","................."+getInformation.getNewGetInformation(context).getI_IP());
                        mLogger.info("setSiteAreaid()--->"+"SiteAreaid--"+jsonObject.getInt("siteAreaid")+"..SiteAreaid().."+MyApplication.getApp().getSiteAreaid());
                        if(jsonObject.getInt("siteAreaid") != MyApplication.getApp().getSiteAreaid()){
                            if(jsonObject.getInt("siteAreaid") != 0){
                                SharedPreferencesUtils.setParam(context, HomeUtil.mFWQ, mFwq);
                            }
                            MyApplication.getApp().setSiteAreaid(jsonObject.getInt("siteAreaid"));
                            MyApplication.getApp().setFWQString(mFwq);
                            saveCombo(context,0,new OnAppSaveComboClickListener() {
                                @Override
                                public void onItemClick(boolean state) {
                                    mLogger.info("更新区域id-->去首页更新UI--->");
                                    MyApplication.getApp().setFWQString(mFwq);
                                    EventBus.getDefault().post("wifl_view");
                                }
                            });

                            if(jsonObject.has("pushIden")){
                                String pushIden =  jsonObject.getString("pushIden");
                                SharedPreferencesUtils.setParam(context,HomeUtil.AppAltairPushIden,pushIden);
                                SharedPreferencesUtils.setParam(context,HomeUtil.AppAltairPushIden_Statr,false);
                                setPushAurora(context);
                            }

                        }
                        Intent intent = new Intent(context,AlarmReceiver.class);
                        intent.putExtra("networking","updateNetwork6");
                        context.sendBroadcast(intent);

                    }else {
                        setSiteAreaidNO(context,type);
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                    setSiteAreaidNO(context,type);
                }
            }

            @Override public void onFailure(Throwable error) {
                setSiteAreaidNO(context,type);
            }
        });
    }

    /**
     * 失败的处理  13:31:45
     */
    private void setSiteAreaidNO(final Context context,int type){
        if(type == 0 || type == 3){
            mLogger.info("开始找代理--->"+"type"+type);
            NetworkChangeAgent.newInstance(context).getIp(new NetworkChangeAgent.OnAgentFWQClickListener() {
                @Override
                public void onFWQ(String fwq) {
                    mLogger.info("开始找代理--结果>onFWQ()--->"+"String--"+fwq);
                    if(fwq.equals("没有查到")){
                        Toast.makeText(context,"没有查找到代理服务器",Toast.LENGTH_SHORT).show();
                    }else {
                        mFwq = fwq;
                        AgentIp.newInstance(context).setNetWorkstate1();
                        setSiteAreaid(context,2);
                    }
                }
            });
        }else if(type == 1 || type == 2){
            Toast.makeText(context,"没有查找到代理服务器",Toast.LENGTH_SHORT).show();
            mLogger.info("更新区域id-->onItemClick()--->"+"没有查找到代理服务器--");
        }
    }

    /**
     * 先域名访问
     * 判断网络是否可行
     */
    public void domainUtil(final Context context,int overtime,final OnHomeUtilClickListener onHomeUtilClickListener){
        String stringJson = "{}"; //参数包
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngVersion_isAlive,stringJson,"null","0",time);
        Map map = StringUtil.getStringUtilNew().getMapNew(context,stringJson,"null","0",Url.mStirngVersion_isAlive,stirngSign,time);
        mLogger.info("domainUtil()--->测试网络"+"fwq--"+MyApplication.mFWQIP);
        GreenTreeNetworkUtil.getInstance().doPost(context,MyApplication.mFWQIP,overtime,map,new RequestDataCallback() {
            @Override public void onSuccess(String response){
                try {

                    JSONObject jsonObject = new JSONObject(response);
                    if (jsonObject.getInt("code") == 1) {
                        mLogger.info("domain()--->onSuccess()--->"+"String--"+response);
                        onHomeUtilClickListener.onItemClick("ok");
                    } else {
                        mLogger.info("domain()--->onSuccess()--->"+"String--"+response);
                        onHomeUtilClickListener.onItemClick("no");
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                    mLogger.info("domain()--->onSuccess()-无网-->");
                    onHomeUtilClickListener.onItemClick("no");
                }
            }

            @Override
            public void onFailure(Throwable error) {
                mLogger.info("domain()--->onFailure()--->失败"+"Throwable--"+error);
                onHomeUtilClickListener.onItemClick("no");
            }
        });
    }

    /**
     *获取模式的接口
     */
    public void saveCombo(final Context context,final int type,final OnAppSaveComboClickListener onAppSaveComboClickListener){
        if(type== 0){
            mSaveComboInt = 0;
        }
        mSaveComboInt++;
        HashMap<String,Object> hashMap = new HashMap<>();
        String token = (String) SharedPreferencesUtils.getParam(context, HomeUtil.mTokenDB, "");
        String id = (String) SharedPreferencesUtils.getParam(context, HomeUtil.mUseridDB, "");
        hashMap.put("userid",id);
        hashMap.put("siteAreaid",MyApplication.getApp().getSiteAreaid());
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(hashMap);
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.getUrlNew().property_payoffWay,stringJson,token,id,time);
        Map map = StringUtil.getStringUtilNew().getMapNew(context,stringJson,token,id,Url.getUrlNew().property_payoffWay,stirngSign,time);
        if(MyApplication.getApp().getSiteAreaid() == 0 ){
            SharedPreferencesUtils.setParam(context,mAppPattern,0);
            ArrayList list =new ArrayList();
            list.add(0);
            SharedPreferencesUtils.setParam(context,mAppPatternArray,list);
            if(onAppSaveComboClickListener != null){onAppSaveComboClickListener.onItemClick(true); }
            return;
        }
        mLogger.info("saveCombo()--->获取模式"+"fwq--"+MyApplication.getApp().getFWQString() + "..stringJson.."+stringJson+"...NF_callid..."+map.get("NF_callid"));
        GreenTreeNetworkUtil.getInstance().doPost(context,MyApplication.getApp().getFWQString(),1,map,new RequestDataCallback() {
            @Override public void onSuccess(String response){
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    if (jsonObject.getInt("code") == 1) {
                        mLogger.info("saveCombo()--->onSuccess()--->"+"String--"+response);
                        JSONArray jsonArray = jsonObject.getJSONArray("pattern");
                        if(jsonArray.length()>0){
                                int i = jsonArray.getInt(0);
                                LogUtil.eE("Logger","..................l........."+i);
                                SharedPreferencesUtils.setParam(context,mAppPattern,i);
                                SharedPreferencesUtils.setParam(context,mAppPatternArray,StringUtil.getStringUtilNew().getPatternList(jsonArray));
                                if(onAppSaveComboClickListener != null){onAppSaveComboClickListener.onItemClick(true); }
                                if(StringUtil.getStringUtilNew().judgeUIType(i) == 1){
                                    JSONObject jsonObject1 = jsonObject.getJSONObject("vip");
                                    if(jsonObject1.getInt("result") == 1){
                                        SharedPreferencesUtils.setParam(context,HomeUtil.mVIPCombonum,jsonObject1.getInt("goodsid"));
                                        SharedPreferencesUtils.setParam(context,HomeUtil.mVIPSTATE,true);
                                        SharedPreferencesUtils.setParam(context,HomeUtil.mPledge,jsonObject1.getInt("pledge"));
                                    }else {
                                        SharedPreferencesUtils.setParam(context,HomeUtil.mVIPSTATE,false);
                                        SharedPreferencesUtils.setParam(context,HomeUtil.mVIPCombonum,0);
                                        SharedPreferencesUtils.setParam(context,HomeUtil.mPledge,0);
                                        if( mSaveComboInt <3 ){
                                            getHandlerNew().postDelayed(new Runnable() {
                                                @Override
                                                public void run() {
                                                    saveCombo(context,2,null);
                                                }
                                            },800);
                                        }
                                    }
                                }else if(StringUtil.getStringUtilNew().judgeUIType(i) == 2){
                                    JSONObject jsonObject1 = jsonObject.getJSONObject("combo");
                                    if(jsonObject1.getInt("result") == 1){
                                        SharedPreferencesUtils.setParam(context,"good_tab",2);
                                        SharedPreferencesUtils.setParam(context,HomeUtil.mVIPCombonum,1);
                                        SharedPreferencesUtils.setParam(context,HomeUtil.mVIPSTATE,true);
                                        LogUtil.eE("VIPSTATE","....925...true..");
                                        if(jsonObject1.has("money")){
                                            SharedPreferencesUtils.setParam(context,HomeUtil.mPledge,jsonObject1.getInt("money"));
                                        }
                                        if(jsonObject1.has("endTime")){
                                            SharedPreferencesUtils.setParam(context,mPackage_Expire_time,jsonObject1.getString("endTime"));
                                        }
                                        if(jsonObject1.has("attachCombo")){
                                            JSONArray jsonArra = jsonObject1.getJSONArray("attachCombo");
                                            LogUtil.eE("Arra",StringUtil.getStringUtilNew().arrayList(jsonArra).toString());
                                            SharedPreferencesUtils.setParam(context,mPackage_AttachCombo,StringUtil.getStringUtilNew().arrayList(jsonArra));
                                        }
                                        if(jsonObject1.has("comboId")){
                                            SharedPreferencesUtils.setParam(context,"vip_comboId",jsonObject1.getInt("comboId"));
                                        }
                                        if(jsonObject.has("deviceCount")){
                                            SharedPreferencesUtils.setParam(context,mPackage_deviceCount,jsonObject.getInt("deviceCount"));
                                        }

                                        if(jsonObject1.has("remainingDays")){
                                            SharedPreferencesUtils.setParam(context,mPackage_RemainingDays,jsonObject1.getInt("remainingDays"));
                                        }

                                    }else {
                                        updateCommodity(context,1,0,0,0,0,0,"");
                                        LogUtil.eE("VIPSTATE","....949...false..");
                                        SharedPreferencesUtils.setParam(context,HomeUtil.mVIPSTATE,false);
                                    }
                                }
                            EventBus.getDefault().post("wifl_view");
                        }else {
                            updateCommodity(context,1,0,0,0,0,0,"");
                            SharedPreferencesUtils.setParam(context,mAppPatternArray,StringUtil.getStringUtilNew().getPatternList(jsonArray));
                            SharedPreferencesUtils.setParam(context,mAppPattern,0);
                            SharedPreferencesUtils.setParam(context,mAppPatternArray,StringUtil.getStringUtilNew().getPatternList(jsonArray));
                            if(onAppSaveComboClickListener != null){onAppSaveComboClickListener.onItemClick(false);
                            }
                        }

                    }else {
                        updateCommodity(context,1,0,0,0,0,0,"");
                        if(onAppSaveComboClickListener != null){onAppSaveComboClickListener.onItemClick(false); }
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                    updateCommodity(context,1,0,0,0,0,0,"");
                    if(onAppSaveComboClickListener != null){onAppSaveComboClickListener.onItemClick(false); }
                }
            }
            @Override
            public void onFailure(Throwable error) {
                updateCommodity(context,1,0,0,0,0,0,"");
                if(onAppSaveComboClickListener != null){onAppSaveComboClickListener.onItemClick(false); }
                mLogger.info("saveCombo()--->onFailure()--->失败"+"Throwable--"+error);
            }
        });
    }

    /**
     *
     */
    private void updateCommodity(Context context,int good_tab,int comboId,int deviceCount,int vIPCombonum,int pledge,int remainingDays,String expireTime){
        SharedPreferencesUtils.setParam(context,"good_tab",good_tab);
        SharedPreferencesUtils.setParam(context,"vip_comboId",comboId);
        SharedPreferencesUtils.setParam(context,mPackage_deviceCount,deviceCount);
        SharedPreferencesUtils.setParam(context,HomeUtil.mVIPCombonum,vIPCombonum);
        SharedPreferencesUtils.setParam(context,HomeUtil.mPledge,pledge);
        SharedPreferencesUtils.setParam(context,mPackage_RemainingDays,remainingDays);
        SharedPreferencesUtils.setParam(context,mPackage_Expire_time,expireTime);
    }


    /**
     * 上传文件
     * 如崩溃信息
     */
    public void pushError(Context context,String path){

        mLogger.info("pushError()--->崩溃信息上传---path"+path);
        final File file = new File(path);
        if(!file.exists()){
            mLogger.info("pushError()--->崩溃信息上传---该文件不存在");
            return;
        }
        Map<String,Object> map = new HashMap<>();
        String id = (String) SharedPreferencesUtils.getParam(context, HomeUtil.mUseridDB,"");
        map.put("file1",file);
        map.put("userid",id);
        map.put("deviceType",getInformation.getNewGetInformation(context).getInfoPhoneType());
        map.put("phone",SharedPreferencesUtils.getParam(context, HomeUtil.mHUWePhone,""));
        map.put("areaid",MyApplication.getApp().getSiteAreaid()+"");
        GreenTreeNetworkUtil.getInstance().doPostFile("http://api.szaltair.com:8080"+ Url.UPLOAD_LOG, map, new RequestDataCallback() {
            @Override
            public void onSuccess(String response) {
            mLogger.info("pushError()--->日志上传结束---String"+response);
                SharedPreferencesUtils.setParam(MyApplication.getApp().getAppContext(), HomeUtil.mCrashError,"");
                ZipUtils.getmZipUtils().deleteFile(file);
            }
            @Override
            public void onFailure(Throwable error) {
                mLogger.info("pushError()--->日志上传失败---Throwable"+error);
            }
        });
    }

    /**
     * 改变首页图片
     */
    private void touristEntry(Context context,String mToken,String chatToken) throws JSONException {
        if ("".equals(mToken)) {
            SharedPreferencesUtils.setParam(context,HomeUtil.mChatToken,chatToken);
        }
        if(mToken.equals("null")){
            JumpActivityUtils.getInstance().jumEntrtPrompt(context);
            return;
        }else {
            SharedPreferencesUtils.setParam(context,HomeUtil.mTokenDB,mToken);
            JumpActivityUtils.getInstance().jumpHome(context,"");
        }
        ((Activity)context).finish();
    }

    /**
     * 获取定位信息
     */
    public void setLocation(final Context context){
        LogUtil.eE("","setLocation........获取定位信息..");
//        AMapLocationClientOption mLocationOption;
//        AMapLocationListener mLocationListener = new AMapLocationListener() {
//            @Override
//            public void onLocationChanged(AMapLocation aMapLocation) {
//                if (aMapLocation != null) {
//                    if (aMapLocation.getErrorCode() == 0) {
//                        String addewss = aMapLocation.getAddress();        //位置
//                        double latitude = aMapLocation.getLatitude();     //获取纬度
//                        double longitude = aMapLocation.getLongitude();  //获取经度
//                        if(latitude !=0){
//                            if(mLocationClient !=null){
//                                uploadLocation(context,latitude+":"+longitude);
//                                mLocationClient.onDestroy();
//                            }
//                        }else {
//                            if(null != mLocationClient){
//                                mLocationClient.onDestroy();
//                            }
//                        }
//                    }
//                }
//            }
//        };

//        mLocationClient = new AMapLocationClient(context.getApplicationContext());
//        mLocationOption = new AMapLocationClientOption();
//        mLocationClient.setLocationListener(mLocationListener);
//        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//        mLocationOption.setInterval(5000);
//        mLocationOption.setWifiActiveScan(false);
//        mLocationOption.setLocationCacheEnable(true);
//        mLocationClient.setLocationOption(mLocationOption);
//        mLocationClient.startLocation();
    }

    /**
     * 上传定位 坐标
     */
    public void uploadLocation(Context context,String mapCoord){
        HashMap mMap = new HashMap<>();
        mMap.put("mapCoord",mapCoord);
        mMap.put("apMac",getInformation.getNewGetInformation(context).getWiFiMac());
        mMap.put("apName",getInformation.getNewGetInformation(context).getWIFIName());
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(mMap); //参数包
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.mStirngVersion_isAlive,stringJson,"null","0",time);
        final Map map = StringUtil.getStringUtilNew().getMapNew(context,stringJson,"null","0",Url.mStirngVersion_isAlive,stirngSign,time);
        mFwq = (String) SharedPreferencesUtils.getParam(context,HomeUtil.mFWQ,"");
        mLogger.info("uploadLocation()--->"+"fwq--"+mFwq+"type--"+"time"+StringUtil.getStringUtilNew().getTimeInstance()+"...stringJson..."+stringJson);
        GreenTreeNetworkUtil.getInstance().doPost(context,mFwq,2000,map,new RequestDataCallback() {
            @Override public void onSuccess(String response) {
                LogUtil.eE("","response"+response);
            }

            @Override public void onFailure(Throwable error) {

            }
        });
    }

    /**
     * 查询 优惠券
     */
    public void getCoupon(final Context context,final OnCouponClickListener onCouponClickListener){
        HashMap Map = new HashMap<>();
        String id = (String) SharedPreferencesUtils.getParam(context,mUseridDB,"");
        String token = (String) SharedPreferencesUtils.getParam(context,mTokenDB,"");
        Map.put("userid",id);
        String stringJson = StringUtil.getStringUtilNew().hashMapToJson(Map);                //参数包
        long time = StringUtil.getStringUtilNew().getTimeCurrent();
        String stirngSign = StringUtil.getStringUtilNew().getSign(Url.getUrlNew().QUERY_COUPON,stringJson,token,id,time);
        Map map = StringUtil.getStringUtilNew().getMapNew(context,stringJson,token,id,Url.getUrlNew().QUERY_COUPON,stirngSign,time);
        mLogger.info("getCoupon()-优惠券-fwq"+MyApplication.getApp().getFWQString()+"stringJson"+stringJson+"...NF_callid..."+map.get("NF_callid"));
        GreenTreeNetworkUtil.getInstance().doPost(context,MyApplication.getApp().getFWQString(),1,map,new RequestDataCallback() {
            @Override public void onSuccess(String response) {
                mLogger.info("getCoupon()--onSuccess().."+response);
                if(onCouponClickListener !=null){
                    onCouponClickListener.onItemClick(response);
                }
            }
            @Override public void onFailure(Throwable error) {
                if(onCouponClickListener !=null){
                    onCouponClickListener.onItemClick("");
                }
                mLogger.info("getCoupon()--onFailure().."+error);
            }
        });
    }

    /**
     * 目前是登录事件之后的回掉
     * 定义接口 用于itme  的回调
     */
    public interface OnHomeUtilClickListener {
        void onItemClick(String type);
    }

    /**
     * 目前是登录事件之后的回掉
     * 定义接口 用于itme  的回调
     */
    public interface OnAppSaveComboClickListener {
        void onItemClick(boolean state);
    }

    /**
     * 目前是登录事件之后的回掉
     * 定义接口 用于itme  的回调
     */
    public interface OnCouponClickListener {
        void onItemClick(String string);
    }

}
